#ifndef TEXTURE_HULL_HPP
#define TEXTURE_HULL_HPP

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/Graphics/Sprite.hpp>

#include <SmegTools/Config.h>

#include "Hull.hpp"

#include <SmegTools/Debug/DebugNew.hpp>

namespace smeg {
    namespace light {
        
////////////////////////////////////////////////////////////
/// Represents a hull with a texture
/// The non transparent pixels will be considered as obstacles
////////////////////////////////////////////////////////////
class TextureHull : public Hull
{
public:
    ////////////////////////////////////////////////////////////
    /// Default Constructor
    ///
    /// \param _Center :        Center of the hull
    /// \param _fAngleDeg :     Rotation angle
    /// \param _bIsStatic :     Static or dynamic ?
    /// \param _pParent :       Shadow caster parent if any
    ///
    ////////////////////////////////////////////////////////////
                                TextureHull( const sf::Vector2f& _Center    = sf::Vector2f(), 
                                            float _fAngleDeg                = 0.0f,
                                            bool _bIsStatic                 = false,
                                            ShadowCasterEntity* _pParent    = NULL );
    ////////////////////////////////////////////////////////////
    /// Constructor with a texture filename
    ///
    /// \param _TextureFilename : Texture to load
    /// \param _Center :        Center of the hull
    /// \param _fAngleDeg :     Rotation angle
    /// \param _bIsStatic :     Static or dynamic ?
    /// \param _pParent :       Shadow caster parent if any
    ///
    ////////////////////////////////////////////////////////////
                                TextureHull( const std::string& _TextureFilename,
                                            const sf::Vector2f& _Center     = sf::Vector2f(), 
                                            float _fAngleDeg                = 0.0f,
                                            bool _bIsStatic                 = false,
                                            ShadowCasterEntity* _pParent    = NULL );
    ////////////////////////////////////////////////////////////
    /// Copy Constructor
    ///
    /// \param _Copy :          Texture hull to copy from
    ///
    ////////////////////////////////////////////////////////////
                                TextureHull( const Hull& _Copy );

    CREATE_CLONE_FUNC(TextureHull, core::BaseEntity)
        
    ////////////////////////////////////////////////////////////
    /// Is the given point inside the hull
    ///
    /// \param _Point :         Point to test
    ///
    /// \return Whether the point is inside the hull or not
    ///
    ////////////////////////////////////////////////////////////
    virtual bool                IsPointInHull( const sf::Vector2f& _p ) const;

    /*********************** Accessors ************************/
    bool                        SetTexture( const std::string& _TextureFilename );
    const sf::Texture&          GetTexture() const;
    
    void                        SetSize( const sf::Vector2f& _size );
    const sf::Vector2f&         GetSize() const;

    void                        SetRepeated( bool _bRepeated );
    bool                        IsRepeated() const;

    void                        SetSmooth( bool _bSmooth );
    bool                        IsSmooth() const;

protected:
    friend class LightSystem;
    
    ////////////////////////////////////////////////////////////
    /// Render the vertices
    ///
    ////////////////////////////////////////////////////////////
    virtual void                RenderVertices() const; 
    
    ////////////////////////////////////////////////////////////
    /// Compute the texture quad to render
    ///
    ////////////////////////////////////////////////////////////
    void                        ComputeQuad();
        
    /******************* Protected members ********************/
    sf::Texture                 m_Texture;
    sf::Vector2f                m_Size;
    sf::Vector2f                m_HalfSize;

#ifdef _DEBUG
public:
    virtual void                DebugRender( const sf::Color& _Color = sf::Color::White );
#endif // _DEBUG
};

/************************** Inline ************************/
inline const sf::Texture& TextureHull::GetTexture() const {
    return m_Texture;
}

inline const sf::Vector2f& TextureHull::GetSize() const {
    return m_Size;
}

    } // smeg::light
} // smeg

#include <SmegTools/Debug/DebugNewOff.hpp>

#endif // TEXTURE_HULL_HPP
